#ifndef __SIPINVITESESSION_HPP__
#define __SIPINVITESESSION_HPP__

#include "WTGDSipService/SipGDServiceConfigure.hpp"
#include "WTGDSipService/SipDlgSessionBase.hpp"
#include "WTGDSipService/SipB2BSession.hpp"

#include "WTResipDll/SipDialogHandle.hpp"

#define HeartBeatInterval 10


namespace wtsip{


class CSipInviteSession;

class WTGD_SIPSRV_PUBLIC CSipRealPlayHandle: virtual public CSipSessionHandle
{
public:

    virtual bool onCancel(SipMessage& msg, CSipInviteSession& invs) = 0;

    virtual bool onCanceled(SipMessage& msg, CSipInviteSession& invs) = 0;

    virtual bool onPtzControl(SipMessage& msg, CSipInviteSession& invs) = 0;

    virtual bool onConnected(SipMessage& msg, CSipInviteSession& invs) = 0;

    virtual bool onDisconnected(CSipInviteSession& invs) = 0;

    virtual bool onTerminated(SipMessage& msg, CSipInviteSession& invs) = 0;

    virtual bool onTerminate(SipMessage& msg, CSipInviteSession& invs) = 0;

    /*virtual bool onPtzOK(SipMessage& msg, CSipInviteSession& invs) = 0;

    virtual bool onPtzFailed(SipMessage& msg, CSipInviteSession& invs) = 0;*/

};


class WTGD_SIPSRV_PUBLIC CSipInviteSession : 
    public CSipDlgSessionBase,
    public CSipInviteDlgHandle
{
public:

    CSipInviteSession(CSipGDService& sv, CSipInviteDialog& dlg);

    virtual ~CSipInviteSession();

    virtual bool start(const std::string& body);

    //virtual bool stop();

    ///////////////////  for b2b control /////////////////////

    const resip::Data invite(const std::string& body);

    bool cancel();

    const resip::Data bye();

    //////////////////////////////////////////////////////////

    resip::Data ptzControl(const std::string& body, int expTime);

    bool replyFailAck();

    bool replyAck();

    //std::string getCurTarget();

    virtual bool messageDresser(SipMessage& msg);

    std::string getRemoteUser();

    std::string getRemoteIP();

	///////////////////////////// CSipDlgHandle methods ////////////////////////

    virtual bool isFakeTransation(SipMessage& msg, CSipDialogBase& dlg);

	virtual bool onResponse(SipMessage& msg, CSipDialogBase& dlg);

	virtual bool onRequest(SipMessage& msg, CSipDialogBase& dlg);

	virtual bool onTimeout(ApplicationMessage& msg, CSipDialogBase& dlg);

	virtual bool onDestroy(CSipDialogBase& dlg);

    ///////////////////////////// CSipInviteDlgHandle methods ////////////////////////

    virtual bool onTrying(SipMessage& msg, CSipInviteDialog& dlg);

    virtual bool onCancel(SipMessage& msg, CSipInviteDialog& dlg);

    virtual bool onCanceled(SipMessage& msg, CSipInviteDialog& dlg);

    virtual bool onFailed(SipMessage& msg, CSipInviteDialog& dlg);

    virtual bool onSucessed(SipMessage& msg, CSipInviteDialog& dlg);

    virtual bool onTerminate(SipMessage& msg, CSipInviteDialog& dlg);

    virtual bool onTerminated(SipMessage& msg, CSipInviteDialog& dlg);

    /////////////////////  CSipB2BSession  methods////////////////////////

    //virtual bool B2BRequest(SipMessage& request);

    //virtual bool B2BResponse(SipMessage& response);

    //virtual bool onB2BRequest(SipMessage& request);

    //virtual bool onB2BResponse(const resip::Data& tid, SipMessage& response);
    
private:

    virtual bool onDestroy();

    bool postHeartBeat(bool staySeq = false);

    ////////////////////// handle list method ////////////////////

    bool handleCancel(SipMessage& msg);

    bool handleCanceled(SipMessage& msg);

    bool handlePtzControl(SipMessage& msg);    

    bool handleTerminated(SipMessage& msg);

    bool handleTerminate(SipMessage& msg);

    bool handleConnected(SipMessage& msg);

    bool handleDisconnected();

private:

	int m_exprAlive;

    //bool m_beatReceived;

    //SipMessage* m_beatMsg;

    int m_beatSeq;

    //CSipRealPlayHandle* m_realhandle;

    //resip::Data m_CurTar;

    //resip::Data m_kpAliveBody;
};



}

#endif


